<template>

	<view class="background">
		<u-popup :show="showPrivacy" :round="10" mode="center" @close="close" @open="open">
			<view class="popupWrap">
				<view class="popupTxt">
					在您使用【香城英才网】之前，请仔细阅读<text class="blueColor"
						@click="handleOpenPrivacyContract">{{privacyContractName}}</text>。如您同意{{privacyContractName}},请点击“同意”开始使用【香城英才网】。
				</view>
				<view class="popupBot">
					<button id="disagree-btn" type="default" @click="handleDisagree">拒绝</button>
					<button id="agree-btn" type="primary" open-type="agreePrivacyAuthorization"
						@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
				</view>
			</view>
		</u-popup>
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<view class="content">
			<view class="my_main_header flex jcsb">
				<view class="flex jcsb aic" style="width: calc(100% - 70px);">
					<view class="my_main_dev">
						<p class="fonts18 fontw700 fontz" style="margin-bottom: 8px;">{{basic.name || "无名氏"}}</p>
						<p class="fonts12 gray">{{basic.phonenumber || "无联系方式"}} | {{basic.jobSearchStatus || "无工作状态"}}</p>
						<p class="fonts12 gray">{{basic.age || "暂无年龄"}} | {{basic.educationLevel||"暂无学历"}} | {{basic.startWorkTime||"暂无工作经历"}}</p>

						<view class="flex jcsb" style="margin-top: 17px;">
							<view class="flex flex_column jcc " @click="details(0)">
								<p class="fonts18 fontw700 fontz">{{basic.deliveredCount}}</p>
								<p class="fonts14 gray  fontz">已投递</p>
							</view>
							<view class="flex flex_column jcc " @click="details(1)">
								<p class="fonts18 fontw700 fontz">{{basic.invitedCount}}</p>
								<p class="fonts14 gray  fontz">邀请投递</p>
							</view>
							<view class="flex flex_column jcc " @click="details(2)">
								<p class="fonts18 fontw700 fontz">{{basic.collectedCount}}</p>
								<p class="fonts14 gray  fontz">收藏</p>
							</view>
						</view>
					</view>
				</view>
				<view class="my_image">
					<image v-if="basic.imageUrl" :src="basic.imageUrl" mode=""></image>
					<image v-else src="../../static/touxiang.png" mode=""></image>
				</view>
			</view>
			<view class="report_main_">
				<view class="report_mains flex aic jcsb" v-for="(item,index) in datas" :key="index"
					@click="detail(item)">
					<view class="flex report_mains_left flex aic">
						<image v-if="item.type==0" src="@/static/fj.png" mode=""></image>
						<image v-if="item.type==1" src="@/static/kb.png" mode=""></image>
						<image v-if="item.type==2" src="@/static/set.png" mode=""></image>
						<image v-if="item.type==3" src="@/static/my1.png" mode=""></image>
						<text class="fonts14 fontz ">{{item.name}}</text>
					</view>
					<image src="@/static/r1.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		getLogin,
		getInfo
	} from "@/api/login"
	import {
		dictFuns
	} from "@/util/dictionary"
	export default {
		data() {
			return {
				showPrivacy: false,
				basic: {
					user: {

					},
				},
				datas: [{
						name: "我的简历",
						type: "0",
						url: "/pages/my/resume/resume"
					},
					{
						name: "投递进度",
						type: "1",
						url: "/pages/my/schedule/schedule"
					}, {
						name: "设置",
						type: "2",
						url: "/pages/my/setting/setting"
					}, {
						name: "意见反馈",
						type: "3",
						url: "/pages/my/opinion/opinion"
					}
				]
			};
		},
		onLoad() {
			wx.getPrivacySetting({
				success: res => {
					console.log("是否需要授权：", res, res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
					if (res.needAuthorization) {
						this.privacyContractName = res.privacyContractName;
						this.showPrivacy = true
					}
				},
				fail: () => {},
				complete: () => {},
			})
		},
		onShow() {
			this.getInfo_()
		},

		methods: {
			handleDisagree(e) {
				this.showPrivacy = false
			},
			handleAgreePrivacyAuthorization(res) {
				// 用户同意隐私协议事件回调
				// 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
				this.showPrivacy = false
				//通知父组件
				this.$emit("agreePrivacy")
				console.log(res, "handleAgreePrivacyAuthorization");
			},
			handleOpenPrivacyContract() {
				// 打开隐私协议页面
				wx.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: (res) => {
						console.log(res, "openPrivacyContract complete");
					}
				})
			},
			getInfo_() {
				getInfo().then(res => {
					console.log("个人信息", res);
					uni.setStorageSync("my_userInfo", res.data)
					this.info()
				})
			},
			info() {
				let obj = uni.getStorageSync("my_userInfo")
				console.log(obj);
				let personalInformation = obj.resumeVo.personalInformation
				let object = {
					phonenumber: obj.user ? obj.user.phonenumber ? obj.user.phonenumber : "" : "",
					name: personalInformation ? personalInformation.fullName ? personalInformation.fullName : "无名氏" :
						"无名氏",
					deliveredCount: obj.deliveredCount,
					invitedCount: obj.invitedCount,
					collectedCount: obj.collectedCount,
					imageUrl: obj.user ? obj.user.avatar ? obj.user.avatar : "" : "",
					age: personalInformation ? personalInformation.age ? personalInformation.age : "暂无年龄信息" : "暂无年龄信息",
					educationLevel: this.educationLevelFun(obj.resumeVo.educationExperiences),
					startWorkTime: this.startWorkTimeFun(personalInformation ? personalInformation.startWorkTime : ""),
					jobSearchStatus: this.jobSearchStatusFun(personalInformation ? personalInformation
						.jobSearchStatus : "")
				}
				this.basic = object
			},
			educationLevelFun(res) {
				if (res.length != 0) {
					console.log(res);
					let number = res[res.length - 1].educationLevel ? res[res.length - 1].educationLevel : ""
					if (number == "") {
						return "暂无学历信息"
					} else {
						if (this.dictFun(number, "education")) {
							return this.dictFun(number, "education")
						} else {
							return "暂无学历信息"
						}

					}
				} else {
					return "暂无学历信息"
				}
			},
			jobSearchStatusFun(res) {
				if (res.length != 0) {
					console.log(res);
					let number = res
					if (number == "") {
						return "暂无工作状态"
					} else {
						if (this.dictFun(number, "status_of_job_hunting")) {
							return this.dictFun(number, "status_of_job_hunting")
						} else {
							return "暂无工作状态"
						}

					}
				} else {
					return "暂无工作状态"
				}
			},
			startWorkTimeFun(res) {
				if (res) {
					let number = 0
					let date = new Date()
					let year = date.getFullYear();
					number = year - res.split("-")[0]
					if (number == 0) {
						return ""
					} else {
						return number + "年工作经验"
					}

				} else {
					return ""
				}
				let date = new Date()
			},
			dictFun(value, res) {
				return dictFuns(value, res)
			},
			details(index) {
				if (index == 0) {
					uni.navigateTo({
						url: "/pages/my/delivered/delivered"
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: "/pages/my/invitation/invitation"
					})
				} else {
					uni.navigateTo({
						url: "/pages/my/collect/collect"
					})
				}
			},
			backLogin() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},

			detail(item) {
				uni.navigateTo({
					url: item.url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popupWrap {
		width: 540rpx;
		box-sizing: border-box;
		padding: 42rpx;
		background: white;
		border-radius: 30rpx;

		.blueColor {
			color: rgba(39, 152, 240, 1);
		}

		.popupTxt {
			line-height: 48rpx;
		}

		.popupBot {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: 30rpx;
		}
	}

	.my_main_header {
		padding-top: 54px;

		.my_image {
			position: relative;

			image {
				width: 70px;
				height: 70px;
				border-radius: 50%;
				margin-top: 6px;
			}
		}

	}

	.my_main_dev {
		width: 80%;
	}

	.report_main_ {
		margin-top: 20px;
	}

	.report_mains {
		padding: 0px 14px;
		height: 60px;
		background: #FFFFFF;
		border-radius: 0px 0px 0px 0px;
		opacity: 1;

		.report_mains_left {
			image {
				width: 16px;
				height: 16px;
				margin-right: 8px;
			}
		}

		image {
			width: 20px;
			height: 20px;
		}
	}
</style>
